package behavioral.strategy;

/**
 * 策略模式
 */

interface Strategy{
    public void Fun();
}


class AStrategy implements Strategy{

    @Override
    public void Fun() {
        System.out.println("Strategy ------------ >   A");
    }
}


class BStrategy implements Strategy{

    @Override
    public void Fun() {
        System.out.println("Strategy ------------ >   B");
    }
}

class CStrategy implements Strategy{

    @Override
    public void Fun() {
        System.out.println("Strategy ------------ >   C");
    }
}

/**
 * 环境类(Context)
 */
class Context{
    private Strategy strategy;

    public Context(Strategy strategy) {
        this.strategy = strategy;
    }

    public void setStrategy(Strategy strategy){
        this.strategy = strategy;
    }

    public void Fun(){
        this.strategy.Fun();
    }
}


class Test{
    public static void main(String[] args) {
        Context context = new Context(new AStrategy());
        context.Fun();

        context.setStrategy(new BStrategy());
        context.Fun();
    }
}